<!--
 * Description: 报价material新增页面
 * Company: 联宝（合肥）电子科技有限公司
 * Author: Dongxu.Ni
 * Date: 2020/04/14 02:52
-->

<template>
  <div>
    <!--数据表单-->
    <el-form label-width="80px" :model="formData" size="mini">
      <el-row>
        <el-col :span="24">
          <!--名称-->
          <el-form-item :label="$t('Material.name')">
            <el-input v-model="formData.name" v-blur:name="formData" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <!--描述-->
          <el-form-item :label="$t('Material.desc')">
            <el-input v-model="formData.desc" v-blur:desc="formData" clearable />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span style="display: block;text-align: center;margin-top: 5px">
      <!--取消按钮-->
      <el-button size="medium" @click="cancel">{{ $t('button.cancel') }}</el-button>
      <!--保存按钮-->
      <el-button :loading="isRequesting" size="medium" type="primary" @click="save">
        {{ $t('button.save') }}
      </el-button>
    </span>
  </div>
</template>

<script>
import { materialAdd } from '@/api/quote/material'

export default {
  name: 'MaterialAdd',
  props: {},
  data() {
    return {
      // 正在查询
      isRequesting: false,
      formData: {}
    }
  },
  methods: {
    async save() {
      try {
        this.isRequesting = true
        await materialAdd(this.formData, { msgSuccess: true, msgError: true })
        this.$emit('save')
      } catch (error) {
        console.log(error)
      } finally {
        this.isRequesting = false
      }
    },
    cancel() {
      this.$emit('cancel')
    }
  }
}
</script>

<style scoped></style>
